package code_smells

import (
    `time`
    `errors`
)

// 特征

type searchRequest struct {
    query string
    start time.Time
    end   time.Time
}

func (request searchRequest) validate() error {
    if request.query == "" {
        return errors.New("query search term is missing 缺少搜索项")
    }
    if request.start.IsZero() || request.start.After(time.Now()) {
        return errors.New("start time is missing or invlid 缺少time参数")
    }
    if request.end.IsZero() || request.end.Before(request.start) {
        return errors.New("end time is missing or invalid")
    }
    return nil
}

type searchResults struct {
    result string
}

func doSearchWithEnvy(request searchRequest) ([]searchResults, error) {
    // valiedate request
    if request.query == "" {
        return nil, errors.New("query is missing 缺少搜索条件")
    }
    if request.start.IsZero() || request.start.After(time.Now()) {
        return nil, errors.New("start time is missing or invlid 缺少time参数")
    }
    if request.end.IsZero() || request.end.Before(request.start) {
        return nil, errors.New("end time is missing or invalid")
    }
    return performSearch(request)
}

func doSearchWithouEnvy(request searchRequest) ([]searchResults, error) {
    err := request.validate()
    if err != nil {
        return nil, err
    }
    return performSearch(request)
}

func performSearch(request searchRequest) ([]searchResults, error) {
    // todo : 未实现
    return nil, errors.New("未实现")
}
